package com.hbt.en_rem_hou.controller;

import com.hbt.en_rem_hou.entitys.Word;
import com.hbt.en_rem_hou.entitys.WordsCondition;
import com.hbt.en_rem_hou.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WordController {

    @Autowired
    public WordService wordService;

    @DeleteMapping("/word/{wordid}")
    public int deleteWordByWordId(@PathVariable("wordid")int wordid){
        return wordService.deleteWordByWordId(wordid);
    }

    @PostMapping("/updateCmd")
    public boolean updateCmd(Word word){
        int size = wordService.updateCmd(word);
        if (size>0){
            return true;
        }else return false;
    }
    @PostMapping("/updateImp")
    public boolean updateImd(Word word){
        int size = wordService.updateImp(word);
        if (size>0){
            return true;
        }else return false;
    }

    @PostMapping("/changeFanyi")
    public boolean changeFanyi(Word word){
        wordService.changeFanyiByWordId(word);
        return true;
    }

    @RequestMapping(value = "/word/{wordid}", method = RequestMethod.GET)
    public Word getWordByWordId(@PathVariable("wordid") int wordid){
        return wordService.getWordByWordID(wordid);
//        return null;
    }

    @RequestMapping("/findWordByCondition")
    public List<Word> findWordByCondition(WordsCondition wordsCondition){
        System.out.println("wordCondition:"+wordsCondition);
        return wordService.getWordByCondition(wordsCondition);
    }

    @RequestMapping("/addWord")
    public boolean addWord(Word word){
        System.out.println("controller add word:"+word);
//        boolean hasSuccess = false;
//        wordService.hasThisWord(word);
        boolean hasSuccess = wordService.addWord(word);
        if (hasSuccess){
            System.out.println("service success");
        }else {
            System.out.println("service fail");
        }
        return hasSuccess;
    }
}
